using System;

using Pegasus.Diagnostics;
using Pegasus.Workflow.Service;

namespace Pegasus.UnitTests.Workflow.Service.Workflows
{
	/// <summary>
	/// The starting state that catches the first event in the event workflow test.
	/// </summary>
	public class StateCallChildWorkflow : WorkflowState
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="T:StateCallChildWorkflow"/> class.
		/// </summary>
		public StateCallChildWorkflow() :
			base( "StateCallChildWorkflow" )
		{
		}

		/// <summary>
		/// Called when the state is entered.
		/// </summary>
		/// <param name="previousState">Previouse state, null if workflow is just starting.</param>
		protected override void OnStateEnter( string previousState )
		{
			base.OnStateEnter( previousState );

			Workflow.StartChildWorkflowEx( typeof( TestChildWorkflow ),
				new EventHandler<WorkflowEventArgs>( ChildWorkflowCompleted ) );
		}

		/// <summary>
		/// Handles the workflow completed event from our child workflows.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="args">The <see cref="T:Pegasus.Workflow.Service2.WorkflowEventArgs"/> instance containing the event data.</param>
		private void ChildWorkflowCompleted( object sender, WorkflowEventArgs args )
		{
			Workflow.WorkflowComplete( 456 );
		}
	}
}
